<?php
  getHeader();
  if (isset($_SESSION['adminPassed']))
  {
	getPanel();
?>

	<ul>
		<li><a href='?p=competitionAdmin&do=createCompetition'>新建比赛</a></li>
		<li><a href='?p=competitionAdmin&do=editCompetition'>编辑比赛</a></li>
	</ul>
	
<?php 
	$action = isset($_GET['do']) ? $_GET['do'] : "";
	
	switch ($action)
	{
		case 'createCompetition':
			{
				if (isset($_POST['createComp']))
				{
					$data['competitionName'] = $_POST['competitionName'];
					$data['competitionAdmin'] = userProf::getUidbyUsername($_POST['competitionAdmin']);
					$data['competitionDescription'] = $_POST['competitionDescription'];
					$data['competitionLevel'] = $_POST['competitionLevel'];
					$data['competitionScore'] = $_POST['competitionScore'];
					$data['competitionLink'] = $_POST['competitionLink'];
					$comp = new compProf($data);
					if ($comp->create())
					{
?>
						<span>创建比赛成功</span>
<?php
					}
					else
					{
?>
						<span>创建比赛失败</span>
<?php 
					}
				}
				else
				{
?>
					<form action="?p=competitionAdmin&do=createCompetition" method="post">
						<input type="hidden" name="createComp" value="yes" />
						比赛名称: <input type="text" name="competitionName" /><br />
						比赛管理员: <input type="text" name="competitionAdmin" /><br />
						比赛描述: <textarea name="competitionDescription" id="tinyInput"></textarea><?php getEditor(); ?><br />
						比赛级别: <input type="text" name="competitionLevel" /><br />
						比赛积分: <input type="text" name="competitionScore" /><br />
						比赛链接: <input type="text" name="competitionLink" />请留空<br />
						<input type="submit" value="创建" onclick="instance.post();"/>
					</form>
<?php
				}
			}
			break;
		default:
			{
			}
	}
  }
  else
  {
?>
	<span>你无权进行管理</span>
<?php 
  }
?>